package cn.xzq.crm.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import cn.xzq.crm.entity.Visit;

@Repository("visitDaoImpl")
public class VisitDaoImpl extends BaseDaoImpl<Visit> implements VisitDao {
	
	
	/**
	 * 添加一条客户拜访记录
	 * @param visit
	 */
	/*public void add(Visit visit){
		hibernateTemplate.save(visit);
	}*/
	
	/**
	 * 查找所有客户拜访记录
	 * @return
	 */
	
	/*@SuppressWarnings("all")
	public List<Visit> findAll(){
		return (List<Visit>) hibernateTemplate.find("from Visit");
	}*/
	
	/**
	 * 根据查找一条拜访记录
	 * @param vid
	 * @return
	 */
	/*public Visit findOneById(String vid){
		List<Visit> list = (List<Visit>) hibernateTemplate.find("from Visit where vid=?", vid);
		if(list == null && list.size()==0){
			return null;
		}
		return list.get(0);
	}*/
	
	/**
	 * 修改一个客户拜访记录
	 * @param visit
	 */
	/*public void update(Visit visit){
		hibernateTemplate.update(visit);
	}*/

	@Override
	public void delete(Visit t) {
	}
	
	
	/** 
	 * 多条件综合查询
	 * @return
	 */
	public List<Visit> findMoreCondition(Visit visit){
		DetachedCriteria criteria = DetachedCriteria.forClass(Visit.class);
		if(visit.getCustomer()!=null && !visit.getCustomer().getCustId().isEmpty()){
			criteria.add(Restrictions.eq("customer.custId", visit.getCustomer().getCustId()));
		}
		if(visit.getUser()!=null && !visit.getUser().getUid().isEmpty()){
			criteria.add(Restrictions.eq("user.uid", visit.getUser().getUid()));
		}
		if(visit.getVaddress()!=null && !visit.getVaddress().isEmpty()){
			criteria.add(Restrictions.like("vaddress", visit.getVaddress()));
		}
		if(visit.getVcontent()!= null && !visit.getVcontent().isEmpty()){
			criteria.add(Restrictions.like("vcontent", visit.getVcontent()));
		}
		List<Visit> list = (List<Visit>) super.hibernateTemplate.findByCriteria(criteria);
		return list;
	}

}
